Newsgroups: comp.lang.python From: Dave Mitchell Subject: Re: Regular expressions, pattern matching Date: Mon, 27 Nov 1995 15:20:51 GMT > > The Python library documentation says that pattern matching is done like > Emacs, and as far as I can see, gives no further explanation. I don't have the > faintest idea how Emacs pattern matching works, or how the various pattern > matching modules/functions interact, so can someone point me to something like > the extensive Perl documentation. > This is copied w/o permission from O'Reilly's perl book, p. 25 . matches any character except newline [a-z0-9] matches any single character of set [^a-z0-9] matches any single character NOT in set \d matches a digit, same as [0-9] \D matches a non-digit, same as [^0-9] \w matches an alphanumeric (word) character [a-zA-Z0-9_] \W matches a non-word character [^a-zA-Z0-9_] \s matches a whitespace char (space, tab, newline...) \S matches a non-whitespace char \n matches a newline \r matches a return \t matches a tab \f matches a formfeed \b matches a backspace (inside [] only) \0 matches a null char \000 also matches a null char because... \nnn matches an ASCII char of that octal value \xnn matches an ASCII char of that hex value \cX matches an ASCII control char \metachar matches the char itself (\|,\.,\*...) (abc) remembers the match for later backreferences \1 matches the first set of parens matched \2 matches whatever the second set of parens matched \3 and so on... x? matches 0 or 1 x's, where x is any of the above x* matches 0 or more x's x+ matches 1 or more x's x{m,n} matches at least m x's but no more than n a,b,c matches all of a, b, and c in order fee|fie|foe matches one of fee, fie, or foe \b matches a word boundary (outside [] only) \B matches a non-word boundary ^ anchors match to the beginning of a line or string $ anchors match to the end of a line or string Dave